package com.fmdj.mis.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.fmdj.common.util.CommonResult;
import com.fmdj.common.util.PageUtils;
import com.fmdj.mis.api.controller.form.SelectDriverAuthInfoForm;
import com.fmdj.mis.api.controller.form.SelectDriverByPageForm;
import com.fmdj.mis.api.controller.form.UpdateDriverRealAuthForm;
import com.fmdj.mis.api.service.DriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/driver")
@Tag(name = "DriverController", description = "司机管理Web接口")
@Slf4j
public class DriverController {
    @Autowired
    private DriverService driverService;

    @PostMapping("/selectDriverByPage")
    @Operation(summary = "司机的分页查询")
    public CommonResult selectDriverPage(@RequestBody @Valid SelectDriverByPageForm form) {
        PageUtils pageUtils = driverService.selectDriverByPage(form);
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, pageUtils);
    }

    @PostMapping("/selectDriverAuthInfo")
    @Operation(summary = "PC端查询司机认证信息")
    public CommonResult selectDriverAuthInfo(@RequestBody @Valid SelectDriverAuthInfoForm form) {
        HashMap result = driverService.selectDriverAuthInfo(form.getRealAuth(), form.getDriverId());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, result);
    }

    @PostMapping("/updateDriverRealAuth")
    @Operation(summary = "更新司机实名认证")
    public CommonResult updateDriverRealAuth(@RequestBody @Valid UpdateDriverRealAuthForm form) {
        int rows = driverService.updateDriverRealAuth(form);
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }
}
